#include "cjson.h"

int main(int argc, char **argv)
{
#if 0
    int res;
    char buffer[CJSON_BUFFER_SIZE] = "";

    res = cjson_init_file("test.json");
    if (-1 == res) {
        perror("json init file error");
        return -1;
    }

    res = cjson_set_data_by_one_level("test.json", "favor", CJSON_FORMAT_STRING, "roocket1");
    if (-1 == res) {
        perror("cjson_set_data_by_one_level error");
        return -1;
    }

    res = cjson_set_data_by_one_level("test.json", "gender", CJSON_FORMAT_STRING, "female");
    if (-1 == res) {
        perror("cjson_set_data_by_one_level error");
        return -1;
    }

    res = cjson_delete_data_by_one_level("test.json", "favor");
    if (-1 == res) {
        perror("cjson_set_data_by_one_level error");
        return -1;
    }

    res = cjson_get_data_by_one_level("test.json", "gender", CJSON_FORMAT_STRING, buffer);
    if (-1 == res) {
        perror("cjson_get_data_by_one_level error");
        return -1;
    }
    memset(buffer, 0x00, CJSON_BUFFER_SIZE);
    double age = 14;
    res = cjson_set_data_by_one_level("test.json", "favor2", CJSON_FORMAT_NUMBER_DOUBLE, &age);
    if (-1 == res) {
        perror("cjson_set_data_by_one_level error");
        return -1;
    }

    double t;
    res = cjson_get_data_by_one_level("test.json", "favor2", CJSON_FORMAT_NUMBER_DOUBLE, &t);
    if (-1 == res) {
        perror("cjson_get_data_by_one_level error");
        return -1;
    }

    int code = 24;
    res = cjson_set_data_by_one_level("test.json", "favor2", CJSON_FORMAT_NUMBER_DOUBLE, &code);
    if (-1 == res) {
        perror("cjson_set_data_by_one_level error");
        return -1;
    }

    int c;
    res = cjson_get_data_by_one_level("test.json", "favor2", CJSON_FORMAT_NUMBER_DOUBLE, &c);
    if (-1 == res) {
        perror("cjson_get_data_by_one_level error");
        return -1;
    }

    printf("the int is %d\n", c);
#endif

#if 0
    // cjson_set_data_by_two_level("test.json", "country1", "city1", CJSON_FORMAT_STRING, "guangzhou1");
    cjson_set_data_by_two_level("test.json", "country2", "city9", CJSON_FORMAT_STRING, "guangzhou8");

    char city[32] = "";
    cjson_get_data_by_two_level("test.json", "country4", "city3", CJSON_FORMAT_STRING, city);
    printf("the city is %s\n", city);

    cjson_delete_data_by_two_level("test.json", "country2", "city8");
    //cjson_set_data_by_two_level("test.json", "country1", "city1", CJSON_FORMAT_STRING, "guangzhou");

#endif

#if 0
    int year;
    cjson_get_data_by_two_level("test.json", "device", "year", CJSON_FORMAT_NUMBER_INT, &year);
    printf("the year of device is %d\n", year);
    
    int month;
    cjson_get_data_by_two_level("test.json", "device", "month", CJSON_FORMAT_NUMBER_INT, &month);
    printf("the month of device is %d\n", month);
    
    double sec;
    cjson_get_data_by_two_level("test.json", "device", "sec", CJSON_FORMAT_NUMBER_DOUBLE, &sec);
    printf("the sec of device is %f\n", sec);
    
    unsigned char ok;
    cjson_get_data_by_two_level("test.json", "device", "ok", CJSON_FORMAT_NUMBER_UNSIGNED_CHAR, &ok);
    printf("the ok of device is %d\n", ok);
#endif
    return 0;
}